package com.cqc.suertextview01;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.Toast;

import com.allen.library.CommonTextView;

/**
 * Created by ${cqc} on 2017/9/11.
 */

public class CommonTextViewActivity extends AppCompatActivity {

    private Context context = this;
    private CommonTextView ctv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle("CommonTextView");
            actionBar.setDisplayHomeAsUpEnabled(true);
//            actionBar.setDisplayShowHomeEnabled(true);
        }
        setContentView(R.layout.activity_common_text_view);

        ctv = (CommonTextView) findViewById(R.id.ctv2);
        ctv.setOnCommonTextViewClickListener(new CommonTextView.OnCommonTextViewClickListener() {
            @Override
            public void onCommonTextViewClick() {
                super.onCommonTextViewClick();
                Toast.makeText(context, "common", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLeftViewClick() {
                super.onLeftViewClick();
                Toast.makeText(context, "left", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCenterViewClick() {
                super.onCenterViewClick();
                Toast.makeText(context, "center", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onRightViewClick() {
                super.onRightViewClick();
                Toast.makeText(context, "right", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }
}
